﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.StopZero.CApStopZeroEmphasizer
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System.Collections.Generic;
using System.Linq;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.StopZero;

public class CApStopZeroEmphasizer
{
  private TxColor _color;
  private TxColorEmphasizePriority _priority;
  private HashSet<ITxDisplayableObject> _emphasizedItems;

  public CApStopZeroEmphasizer(TxColor color, TxColorEmphasizePriority priority)
  {
    this._color = new TxColor(color);
    this._priority = priority;
    this._emphasizedItems = new HashSet<ITxDisplayableObject>();
  }

  public void SetEmphasizedItems(List<ITxObject> itemsToEmphasize)
  {
    HashSet<ITxDisplayableObject> displayableObjectSet = new HashSet<ITxDisplayableObject>(itemsToEmphasize.Cast<ITxDisplayableObject>());
    this._emphasizedItems.ExceptWith((IEnumerable<ITxDisplayableObject>) displayableObjectSet);
    this.Unemphasize((IEnumerable<ITxDisplayableObject>) this._emphasizedItems);
    this.EmphasizeIfUnemphasized((IEnumerable<ITxDisplayableObject>) displayableObjectSet);
    this._emphasizedItems = displayableObjectSet;
    TxApplication.RefreshDisplay();
  }

  public void UnemphasizeAllEmphasized()
  {
    this.Unemphasize((IEnumerable<ITxDisplayableObject>) this._emphasizedItems);
    this._emphasizedItems.Clear();
    TxApplication.RefreshDisplay();
  }

  private void EmphasizeIfUnemphasized(IEnumerable<ITxDisplayableObject> itemsToEmphasize)
  {
    foreach (ITxDisplayableObject displayableObject in itemsToEmphasize)
    {
      if (!this._emphasizedItems.Contains(displayableObject))
        TxDisplayableObjectEx.EmphasizeObject(displayableObject, this._color, this._priority);
    }
  }

  private void Unemphasize(
    IEnumerable<ITxDisplayableObject> itemsToUnemphasize)
  {
    foreach (ITxDisplayableObject displayableObject in itemsToUnemphasize)
      TxDisplayableObjectEx.StopEmphasizeObject(displayableObject, this._color, this._priority);
  }
}
